package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.Lists;
import com.iwhalecloud.bss.kite.client.dto.DataResult;
import com.iwhalecloud.bss.kite.cucc.client.api.goods.IGoodsService;
import com.iwhalecloud.bss.kite.cucc.client.dto.goods.GoodPriceAttrReqDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.goods.GoodPriceReqDTO;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.GlowedNodePriceStandardServiceAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.scene.attr.OperateInstAttrService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author zhoubang
 * 云聚节点-资费信息-节点费标准资费（元/月）属性联动
 */
@Service
@AttrHandler(GlowedNodePriceStandardServiceAttrHandler.class)
public class GlowedNodePriceStandardServiceAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {
    @Autowired
    IQuerySceneInstService querySceneInstService;

    @Autowired
    OperateInstAttrService operateInstAttrService;

    @Autowired
    private IGoodsService goodsService;

    @Override
    public void handle(KiteAttr kiteAttr, KiteInst inst, AttrData data) {

        String sceneInstId = data.getSceneInstId();
        List<KiteProdInst> kiteProdInstList = querySceneInstService.listProdInsts(sceneInstId);
        for (KiteProdInst kiteProdInst : kiteProdInstList) {
            if ("63249782".equals(kiteProdInst.getSpecId())) {     //63249782为云聚节点套件框架的prodId
                KiteAttr typeKiteAttr = kiteProdInst.getAttr("200001914");

                List<GoodPriceAttrReqDTO> propertyValue = Lists.newArrayList();
                GoodPriceAttrReqDTO goodPriceAttrReq = new GoodPriceAttrReqDTO();
                goodPriceAttrReq.setAttr(typeKiteAttr.getFieldName());
                goodPriceAttrReq.setAttrVal(typeKiteAttr.getValue());
                propertyValue.add(goodPriceAttrReq);
                GoodPriceReqDTO goodPriceReq = new GoodPriceReqDTO();
                goodPriceReq.setSKU("50041846");
                goodPriceReq.setPropertyValue(propertyValue);
                // 查询价格
                DataResult<String> result = goodsService.queryGoodPrice(goodPriceReq);
                kiteAttr.setValueDesc(result.getResultObject());
                kiteAttr.setValue(result.getResultObject());
                break;
            }
        }
    }

    @Override
    public void handleStyle(KiteAttr kiteAttr, KiteInst kiteInst, AttrData data) {

    }

}
